import React from 'react';
import ReactDOM from 'react-dom';
import { HashRouter as Router, Switch, Route, Link, HashHistory, Redirect  } from 'react-router-dom';

import Bundle from './bundle'

import App from './App';
import Login from './pages/login/login';
import AppState from './store/message';

//异步加载bundle
import Message from 'bundle-loader?lazy!./pages/message/message'
import NoMatch from 'bundle-loader?lazy!./components/error/err404'

const appState = new AppState();

ReactDOM.render((
  <Router history={HashHistory}>
    <App appState={appState}>
      <Switch>
        <Route exact path="/" component={Login} />{/*入口路由不能用异步，因为异步会导致还没有return会报错*/}
        <Route path="/message" component={ props => <Bundle load={Message} >{ Test => <Test appState={appState} />}</Bundle> } />
        <Route component={ props => <Bundle load={NoMatch}>{ Test => <Test />}</Bundle> } />
        <Redirect from="/*" to="/404" />
      </Switch>
    </App>
  </Router>),
document.getElementById('app'));